extends Enemy
@onready var look_down:RayCast2D = $Sprite2D/LookDown
@onready var look_forward:RayCast2D =  $Sprite2D/LookForward

func deadth():
	animation_player.play("death")

func was_killed():
	_tween_scale(Vector2(0.55,0.2))

func _tween_scale(target):
	var tween = get_tree().create_tween()
	tween.set_parallel(false)
	tween.set_ease (Tween.EASE_IN_OUT)
	tween.tween_property($Sprite2D, "scale", target, 0.1)

# 设置面部朝向 : 这个实现太麻烦，其实使用scale.x = -1更好
func set_face_direction(face_direction):
	sprite.scale.x = -face_direction * 0.5

# 发现了什么东西
func look_something() -> int:
	if look_forward.is_colliding():
		var colider := look_forward.get_collider()
		if colider is TileMap:
			return 1
		elif colider is Player:
			return 2
		else:
			return 0
	return 0

# 发现了悬崖
func look_falling():
	return not look_down.is_colliding()
